package com.aholu.wicket.pages;

import java.util.Date;

import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.datetime.StyleDateConverter;
import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.convert.converter.DateConverter;

import com.aholu.dao.UserDao;
import com.aholu.model.User;
import com.aholu.wicket.WebSession;

@AuthorizeInstantiation("standart")
public class HomePage extends WebPage {

	private final Date date;
	public Date getDate() {
		
		return date;
	}

	private final Date time = new Date();

	public HomePage() {
		
		

		User user = ((WebSession) AuthenticatedWebSession.get()).getLoggedUser();
		
		date = user.getDate();

		final TextField<String> userName = new TextField<String>("username", Model.of(""));
		userName.setModelValue(new String[] { user.getUserName() });
		final TextField<String> password = new TextField<String>("password", Model.of(""));
		password.setModelValue(new String[] { user.getPassword() });
		final TextField<String> name = new TextField<String>("name", Model.of(""));
		name.setModelValue(new String[] { user.getName() });
		final TextField<String> surname = new TextField<String>("surname", Model.of(""));
		surname.setModelValue(new String[] { user.getSurName() });
		final TextField<String> email = new TextField<String>("email", Model.of(""));
		email.setModelValue(new String[] { user.getEmail() });

		DateTextField dateTextField = new DateTextField("dateTextField", new PropertyModel<Date>(this, "date")) {

		};
		final Link<String> link = new Link<String>("exit") {
			
			@Override
			public void onClick() {
				setResponsePage(LoginPage.class);
			}
		};

		Form<?> form = new Form<Void>("editForm") {

			@Override
			protected void onSubmit() {
				super.onSubmit();
				setResponsePage(EditPage.class);
			}
		};

		form.add(password);
		form.add(userName);
		form.add(name);
		form.add(surname);
		form.add(email);
		form.add(dateTextField);
		add(link);
		add(form);

	}
}
